/*************************************************
Author: will
Date: 8/23/2012
Description:
Notes: 
*************************************************/

#ifndef __CBattleMgr_h__
#define __CBattleMgr_h__

#include "CBattleInf.h"
#include "CBattleMap.h"
#include "CBattleRole.h"
#include "CBattleRules.h"
#include "CBattleVideo.h"
#include "CBattleRoundCtrl.h"
#include "CBattleActionCtrl.h"

class MsgBattleResult;
class CMonsterGroupConfigData;
class CPlayerBaseInfo;
class CPlayerDetailInfo;
class CPlayerOnlineData;
class CSkillMgr;
class CPartnerUnit;
class CPartnerCfgData;
class CMonsterGroupMember;
class CBattleRoleList;
class CSkillEffect;
class MsgBattleScore;

class CBattlePvPData
{
public:
    CBattlePvPData()
    {
        Clear();
    }

    void Clear()
    {
        _auiLeftRole.Clear();
        _auiRightRole.Clear();
    }

    virtual ~CBattlePvPData() 
    {
    }

public:
    CTLib::CTArray<unsigned int, MAX_BATTLE_ROLES_PER_SIDE> _auiLeftRole;
    CTLib::CTArray<unsigned int, MAX_BATTLE_ROLES_PER_SIDE> _auiRightRole;
};

class CBattleMgr
{
public:
    CBattleMgr()
    {
        BATTLE_INF->_pstMap = &_stMap;
        BATTLE_INF->_pstRoles = &_stRoles;
        BATTLE_INF->_pstRules = &_stRules;
        BATTLE_INF->_pstVideo = &_stVideo;
        BATTLE_INF->_pstRoundCtrl = &_stRoundCtrl;
        BATTLE_INF->_pstActionCtrl = &_stActionCtrl;
    }

    virtual ~CBattleMgr() 
    {
    }

    int GetBattleActType() const {return _iActType;}

    int GetBattleRoleCount() const {return _stRoles.GetRoleCount();}

    bool IsValidRoleID(int iBattleID)
    {
        return _stRoles.IsValidRoleID(iBattleID);
    }
    CBattleRole& GetBattleRole(int iRoleID){return _stRoles.GetRole(iRoleID);}

    void SetRightDeadBomb(bool bVal) {_stRoles.SetRightDeadBomb(bVal);}

    int SkillPreEffectDataCalc(int& iPreData, int iBase,
            CSkillEffect& stSkillEffect);

    int DealBattleScore(bool bIsLeft, int& iAttackScore, int& iDefendScore);

    int DealBattleScore(MsgBattleScore& stBattleScore);

    int DoBattle(MsgBattleResult& stMsgBattleRes);

    int TransBattleMsg(MsgBattleResult& stMsgBattleRes);

    int ProcessBattle(MsgBattleResult& stMsgBattleRes);

    int TransPlayerAndPartner(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, CBattleRoleList& stRoleList,
            bool bIsLeft);

    int TransPlayer(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, CBattleRoleData& stRoleData,
            bool bIsLeft);

    int TransMatrixPartner(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, CBattleRoleList& stRoleList,
            bool bIsLeft);

    int TransPartner(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, CPartnerActData& stActData,
            CPartnerUnit& stPartner, CPartnerCfgData& stCfgData,
            CBattleRoleData& stRoleData, int iGridPos, unsigned char ucOrder,
            bool bIsLeft);

    int TransGroupMonster(CMonsterGroupConfigData& stMonGroup,
            CBattleRoleList& stRoleList, bool bIsLeft);

    int TransMonster(CMonsterGroupMember& stMonMember,
            CBattleRoleData& stRoleData, bool bIsLeft);
    
    int AddPlayer(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, bool bIsLeft);

    int AddPartner(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, bool bIsLeft);

    int AddMonster(CMonsterGroupConfigData& stMonGroup, bool bIsLeft);

    int AddPvPObj(unsigned int uiGID, bool bAddPartner, bool bIsLeft);

    int CheckBattleCoolingID(unsigned int uiGID);
    int AddBattleCoolingID(unsigned int uiGID);

    int DealBattle(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CMonsterGroupConfigData& stMonGroup,
            MsgBattleResult& stMsgBattleRes, int iActType);

    int DealPvPBattle(CBattlePvPData& stPvPData,
            MsgBattleResult& stMsgBattleRes, int iActType);

    int DealPvPBattle(CBattleRoleList& stLeftRoleList,
            CBattleRoleList& stRightRoleList, MsgBattleResult& stMsgBattleRes,
            int iActType);

    int DealWorldBoss(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CMonsterGroupConfigData& stMonGroup,
            MsgBattleResult& stMsgBattleRes, int iActType);

    static void GetBattleVideoKey(unsigned int uiGID, int iTypeID,
            T_VIDEO_KEY& szVideoKey);

    //状态目标选择流程(在地图或目标列表中找)
    int StatusTargetChoose(CBattleRole& stBattleRole,
            CSkillAffect& stSkillAffect, MAP_GRID_MULTI& stMapGridMulti)
    {
        return _stRules.StatusTargetChoose(stBattleRole, stSkillAffect,
                stMapGridMulti);
    }

    int StatusSkillEffect(CBattleRole& stBattleRole,
        CBattleRole& stBattleTarget, CSkillAffect& stSkillAffect,
        CStatusObj& stStatusObj, int iAuxAddNum)
    {
        return _stRules.StatusSkillEffect(stBattleRole, stBattleTarget,
                stSkillAffect, stStatusObj, iAuxAddNum);
    }

    void StatusBattleVideo(int iRoleID, int iTreasureID, int iBaseVal,
            int iChgByLvl)
    {
        _stVideo.RoleTreasureAct(iRoleID, iTreasureID, iBaseVal, iChgByLvl);
    }

    void StatusMountVideo(int iRoleID, int iMountID, int iBaseVal,
            int iChgByLvl)
    {
        _stVideo.RoleMountAct(iRoleID, iMountID, iBaseVal, iChgByLvl);
    }

    void GroupCmdStart()
    {
        _stVideo.GroupCmdStart();
    }

    void GroupCmdStop()
    {
        _stVideo.GroupCmdStop();
    }

    void RoleDead(int iRoleID)
    {
        _stVideo.RoleDead(iRoleID);
    }

    int GetRuleStat()
    {
        return _stRules.GetRuleStat();
    }
    int GetSkillType()
    {
        return _stRules.GetSkillType();
    }

    void DumpPlayerAttr(CPlayerAttr& stRoleAttr);

private:
    void SetBattleActType(int iType){_iActType = iType;}

private:
    int                     _iActType;//活动类型
    CBattleMap              _stMap;
    CBattleRoles            _stRoles;
    CBattleRules            _stRules;
    CBattleVideo            _stVideo;
    CBattleRoundCtrl        _stRoundCtrl;
    CBattleActionCtrl       _stActionCtrl;
};

#endif // __CBattleMgr_h__

